package org.tabcap.gui.menu.file;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import org.tabcap.TCInstance;

import static java.awt.event.InputEvent.*;

public class TCFileMenu extends JMenu
{
	private static final long serialVersionUID = -5025706726629036744L;

	public TCFileMenu(TCInstance manager)
	{
		super("File");
		addOption("New", manager.newAction(), 'N', CTRL_DOWN_MASK);
		addOption("Open...", manager.openAction(), 'O', CTRL_DOWN_MASK);
		//add(new JMenuItem("Recent Files"));
		addSeparator();
		addOption("Save", manager.saveAction(), 'S', CTRL_DOWN_MASK);
		addOption("Save As...", manager.saveAsAction());
		addOption("Save All", manager.saveAllAction(), 'S', CTRL_DOWN_MASK | SHIFT_DOWN_MASK);
		//addSeparator();
		//addOption(new JMenuItem("Print"));
	}
	
	public void addOption(String name, ActionListener listener)
	{
		JMenuItem option = new JMenuItem(name);
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, Character keyChar, int modifiers)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyChar, modifiers));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
}